package com.shop.user.api.controller;

import com.shop.common.model.param.user.UserPayLogInput;
import com.shop.common.tmpl.BaseController;
import com.shop.common.util.SessionUtils;
import com.shop.common.util.excption.UserNotFoundException;
import com.shop.user.api.api.IAccountApi;
import com.shop.user.api.service.IUserPaySvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description:
 *
 * @author zhoulk
 * @date: 2019年04月15日  15:41
 */
@RestController
public class AccountController extends BaseController implements IAccountApi {
    @Autowired
    IUserPaySvc iUserPaySvc;
    @Autowired
    SessionUtils sessionUtils;

    @Override
    public String qryAccount(HttpServletRequest request) throws UserNotFoundException {
        Integer userId = sessionUtils.USER_ID(request);
        return returnSvc(iUserPaySvc.qryUserPayOutput(userId));
    }

    @Override
    public String qryLogs(UserPayLogInput input, HttpServletRequest request) throws UserNotFoundException {
        Integer userId = sessionUtils.USER_ID(request);
        input.setUserId(userId);
        return returnSvc(iUserPaySvc.qryUserPayLog4P(input));
    }

    @Override
    public String addIntegralRecharge(@RequestBody Map<String, Object> map, HttpServletRequest request) throws UserNotFoundException {
        Integer userId = sessionUtils.USER_ID(request);
        String payPwd = (String) map.get("payPwd");
        Integer integral = (Integer) map.get("integral");
        return returnSvc(iUserPaySvc.addIntegralRecharge(payPwd,integral,userId));
    }
}
